// *************************************************************************************************
//
// MK3D Engine
// --------------------------------------
// Copyright (C) 2007-2011 Zeb (mailto: zebbey@gmail.com)
//
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
//
// *************************************************************************************************

#include "mk_header.h"
#include "mk_mp_fog.h"
#include "mk_shader.h"

namespace MK3DE
{
	BOOL CMPFog::_s_DefaultEnable = FALSE;
	float CMPFog::_s_DefaultFogStart = 1500.0f;
	float CMPFog::_s_DefaultFogEnd	 = 4000.0f;
	D3DXCOLOR CMPFog::_s_DefaultFogColor(0.6f, 0.6f, 0.6f, 1.0f);

	CMPFog::CMPFog() : _fogColor(_s_DefaultFogColor)
	{
		_bNeedToSet = _s_DefaultEnable;
		_bEnable = _s_DefaultEnable;
		_fogStart = _s_DefaultFogStart;
		_fogEnd = _s_DefaultFogEnd;
	}

	void CMPFog::SetFog(BOOL bEnable, float fogStart, float fogEnd, D3DXCOLOR& fogColor)
	{
		_bEnable = bEnable;
		_fogStart = fogStart;
		_fogEnd = fogEnd;
		_fogColor = fogColor;

		_bNeedToSet = bEnable;
	}

	void CMPFog::GetFog(BOOL& bEnable, float& fogStart, float& fogEnd, D3DXCOLOR& fogColor)
	{
		bEnable = _bEnable;
		fogStart = _fogStart;
		fogEnd = _fogEnd;
		fogColor = _fogColor;
	}

	void CMPFog::OnSetShaderConstant(CShader* pShader, CScene* pScene)
	{
		if (_bNeedToSet)
		{
			pShader->SetFloatArray(SCN_FOG_START, &_fogStart, 1);
			pShader->SetFloatArray(SCN_FOG_END, &_fogEnd, 1);
			pShader->SetFloatArray(SCN_FOG_COLOR, (float*)_fogColor, 4);
		}
	}
}